from rest_framework import serializers

from HttpTestcase.serializers import TestSuiteModuleSerializer
from apps.HttpTestcase.models.testsuite_set import TestsuiteSet
from apps.HttpTestcase.serializers.project import ProjectModuleSerializer


class TestsuiteSetListModeSerializer(serializers.ModelSerializer):
    testsuite = serializers.SerializerMethodField()
    project = ProjectModuleSerializer()
    create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)
    update_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)

    def get_testsuite(self, obj):
        result = obj.testsuite.values('id', 'name', 'is_delete')
        return result

    class Meta:
        model = TestsuiteSet
        fields = '__all__'


class TestsuiteSetModeSerializer(serializers.ModelSerializer):
    class Meta:
        model = TestsuiteSet
        fields = '__all__'
